module.exports = function ($scope, $state, $resource, $modal, toaster ){
    $scope.tour_list = function (pageNo){
        var para = {
            'pageNo': pageNo || $scope.currentPage,
            'pageSize': $scope.itemsPerPage,
            'name':$scope.searchform.name,
            'discount_type':$scope.searchform.discount_type
        }
        
          $scope.info = [];
    
          $resource('/api/as/goc/citydiscount/findList', {}, {}).save(para,function (res) {
        
            if (res.errcode !== 0) {
              alert("数据获取失败");
              return;
            }
            $scope.list = res.data.results;
            

          });
    } 
   
    init();
    //初始化列表
    function init(){
        $scope.currentPage = 1;		//当前页码
        $scope.itemsPerPage = 10;	//每页显示几条
        $scope.searchform = {};
        $scope.tour_list();
    }
    //创建修改
    $scope.setDiscount = function(info) {
        
        var modalInstance = $modal.open({
        template: require('../views/subsidyinfo.html'),
        controller: 'subsidyinfo',
        size: 'lg',
        resolve: {
            item : function () {
                return info;
            },
            flag : function () {
                return info == 1;
            }
        }
        });
        
        //关闭模态框刷新页面
        modalInstance.result.then(function() {
            init();
        });
    }
    $scope.delete = function(id) {
        if(confirm('确认删除吗?')){
          $resource('/api/as/goc/citydiscount/del', {}, {}).save({'id': id}, function(res){
            if (res.errcode === 0) {
              toaster.success({title: '', body: '删除成功'});
              init();
            }else{
              toaster.error({title: '', body: res.errmsg});
            }
          });
        }
      }


};